#include "imgfileutils.h"
#include <QImage>
#include <QDir>
// #include "../arntInclude/arntimage.h"
ImgFileUtils::ImgFileUtils(QObject *parent)
    : QObject{parent}
{
    // AllocImageOperator(&pImgOperator);
}

ImgFileUtils::~ImgFileUtils()
{
    // FreeImageOperator(&pImgOperator);
}



wchar_t *QString2Wchar(QString buf)
{
    return (wchar_t*)reinterpret_cast<const wchar_t *>(buf.utf16());
}

bool ImgFileUtils::ReadPNGFromIMG(QString FilePath,QString saveFilePath,QString saveFileName,qint32 L,qint32 R,qint32 T,qint32 B)
{
    QDir dir;
    if (!dir.exists(saveFilePath)) {
        if (!dir.mkpath(saveFilePath)) {
            qDebug() << "Failed to create directory: " << saveFilePath;
            return false;
        }
    }


    qint32 dL = qAbs(L);
    qint32 dR = qAbs(R);
    qint32 dT = qAbs(T);
    qint32 dB = qAbs(B);
    qint32 dW = qAbs(dR - dL);
    qint32 dH = qAbs(dB - dT);

    /*
    QString totalPath = saveFilePath + "//" + saveFileName;
    ImgDataHeadExt header;
    GrayBmpData data;
    pImgOperator->ReadSubImg(QString2Wchar(FilePath),header,dL,dR,dT,dB,data);
    QImage image(data.pImgData,dW,dH,QImage::Format_Indexed8);
    qDebug()<<totalPath;
    image.save(totalPath);
    */
    return true;
}


